require('../../assets/css/index.less');
require('../../assets/css/basic.less');
// 小图标
require('../../assets/fonts/iconfont.css');
// 当前页面样式
require('./home.less');
// 轮播图
import Swiper, { Pagination, Autoplay } from 'swiper';
import 'swiper/swiper-bundle.css';


console.log(Swiper);
// 工具函数 utils
const dom = require('../../utils/dom');
const https = require('../../utils/https');

dom.ready(function() {
    dom.creatfoot('home');
    // 轮播图
    Swiper.use([Pagination, Autoplay]);
    new Swiper('.swiper', {
        // direction: 'vertical', // 垂直切换选项
        loop: true, // 循环模式选项
        autoplay: true,

        // 如果需要分页器
        pagination: {
            el: '.swiper-pagination',
        },

    });



    //获取信息
    function getUserInfo() {
        https.get('/api/user/info', function(res) {
            let { errno, data } = res;
            if (errno == 0) {
                let { ranking, badges } = data
                // console.log(ranking, badges);
                // console.log(dom.getEle("#ranking"));
                dom.getEle("#ranking").innerHTML = ranking;
                // dom.getEle("#clockCount").innerHTML = data.clockCount;
                dom.getEle("#badges").innerHTML = badges;
            }
        })
    };
    getUserInfo();

    //打卡信息
    function getClock() {
        https.get("/api/user/clockInInfo", function(res) {
            let { errno, data } = res;
            if (errno == 0) {
                dom.getEle("#clockBtn").innerHTML = data.isClockIn ? '已经打卡' : '今日打卡';
                dom.getEle("#clockCount").innerHTML = data.clockCount;
            }
        })
    }
    getClock();

    dom.addEvent("#clockBtn", "click", function() {
        https.post("/api/user/clockIn", {}, function(res) {
            if (res.errno == 0) {
                alert("打卡成功");
                getClock();
            } else {
                alert("打卡失败,今日已打卡");
            }
        })
    })

    //
    dom.addEvent(".sportdata", "click", function() {
        location.href = './sportData.html'
    })
    dom.addEvent(".badge", "click", function() {
        location.href = './badges.html'
    })
    dom.addEvent(".classtrain", "click", function() {
        location.href = './course.html'
    })
    dom.addEvent(".outrun", "click", function() {
        location.href = './countdown.html'
    })

})